//
//  HomeChatView.swift
//  角色列表
//
//  Created by 小柠檬🍋 on 2025/9/7.
//

import SwiftUI

struct AiCustomView2: View {
    @StateObject var viewModel = AiCustom2ViewModel()
    
    var body: some View {
        ZStack{
            if !viewModel.status.isEmpty {
                HomeEmptyView(text1: viewModel.status,text2: viewModel.status2)
                    .frame(maxWidth: .infinity, maxHeight: .infinity)
            } else {
                ZStack{
                    ScrollView {
                        Spacer(minLength: 10)
                        //需要嵌套一层LazyVStack，不然会产生间距，而且大小还会随机
                        LazyVStack(spacing: 15) {
                            ForEach(viewModel.items,id: \.objectId) { item in
                                ApiCustomItemView(bean: item)
                            }
                        }
                    }
                    .enableRefresh()
                    .scrollIndicators(.hidden) // 隐藏滚动条
                    .padding(.horizontal, 20)
                }
            }}
        .navigationTitle("自定义API")
            .frame(maxWidth: .infinity)
            .background(.bg)
            .toolbar {
                // 添加一个右标题按钮
                ToolbarItem(placement: .navigationBarTrailing) {
                    Text("新建")
                        .foregroundColor(themeManager.themeColor)
                        .font(.system(size: 12))
                        .padding(.horizontal,10)
                        .padding(.vertical,7)
                        .cornerRadius(8)
                        .contentShape(Rectangle())
                        .onTapGesture {
                            pathManager.jump(type: JumpType.AI_CUSTOM_CREATE)
                        }
                }
            }
        .onAppear{
            //需要每次都有加载
            viewModel.getData(true)
        }
    }
}

//#Preview {
//    ChatListView()
//}

//定义预览提供者
struct AiCustomView2_Previews: PreviewProvider {
    static var previews: some View {
        //使用预览共享配置
        configurePreviewEnvironment(for: AiCustomView2())
    }
}
